package stools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Date;

public class LineCount {
	public static void main(String[] args) throws Exception {
		String directoryString = "/home/dsw/workspaces/workspace07/analysis/";
		int count = 0;
		count = search(0, directoryString);
		System.out.println("共找到" + count + "行");
		System.out.println(new Date());
	}

	public static int search(int count, String fileString) throws Exception {
		File file = new File(fileString);
		fileString = "/home/dsw/log/search.log";
		if (file.isDirectory()) {
			File subFiles[] = file.listFiles();
			for (File subFile : subFiles) {
				count = search(count, subFile.toString());
			}
		} else {
			if (file.toString().endsWith("java")) {
				FileInputStream fis = new FileInputStream(file);
				InputStreamReader isr = new InputStreamReader(fis);
				BufferedReader br = new BufferedReader(isr);

				String str = null;
				int i = 0;
				boolean flag = true;
				while (null != (str = br.readLine())) {
					i++;
					count++;
				}
				br.close();
				isr.close();
				fis.close();
			}
		}

		return count;
	}

}